'\" te
.\"  Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH ADBGEN 8 "Feb 17, 2023"
.SH NAME
adbgen \- generate adb script
.SH SYNOPSIS
.nf
\fB/usr/lib/adb/adbgen\fR [\fB-m\fR \fImodel\fR] \fIfilename\fR.adb .\|.\|.
.fi

.SH DESCRIPTION
\fBadbgen\fR makes it possible to write \fBadb\fR(1) scripts that do not
contain hard-coded dependencies on structure member offsets. The input to
\fBadbgen\fR is a file named \fIfilename\fR\fB\&.adb\fR that contains header
information, then a null line, then the name of a structure, and finally an
\fBadb\fR script. \fBadbgen\fR only deals with one structure per file; all
member names are assumed to be in this structure. The output of \fBadbgen\fR is
an \fBadb\fR script in \fIfilename\fR. \fBadbgen\fR operates by generating a C
program which determines structure member offsets and sizes, which in turn
generate the \fBadb\fR script.
.sp
.LP
The header lines, up to the null line, are copied verbatim into the generated C
program. Typically, these are \fB#include\fR statements, which include the
headers containing the relevant structure declarations.
.sp
.LP
The \fBadb\fR script part may contain any valid \fBadb\fR commands (see
\fBadb\fR(1)), and may also contain \fBadbgen\fR requests, each enclosed in
braces (\fB\|{\|}\fR\|). Request types are:
.RS +4
.TP
.ie t \(bu
.el o
Print a structure member. The request form is
\fB{\fR\fImember\fR\fB,\fR\fI\|format\fR\fB}.\fR \fImember\fR is a member name
of the \fIstructure\fR given earlier, and \fBformat\fR is any valid \fBadb\fR
format request or any of the \fBadbgen\fR format specifiers (such as
\fB{POINTER}\fR) listed below. For example, to print the \fBp_pid\fR field of
the \fIproc\fR structure as a decimal number, you would write \fB{p_pid,d}\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
Print the appropriate \fBadb\fR format character for the given \fBadbgen\fR
format specifier. This action takes the data model into consideration. The
request form is \fB{\fR\fIformat specifier\fR\fB}.\fR The valid \fBadbgen\fR
format specifiers are:
.RS

.sp
.ne 2
.na
\fB\fB{POINTER}\fR\fR
.ad
.RS 14n
pointer value in hexadecimal
.RE

.sp
.ne 2
.na
\fB\fB{LONGDEC}\fR\fR
.ad
.RS 14n
long value in decimal
.RE

.sp
.ne 2
.na
\fB\fB{ULONGDEC}\fR\fR
.ad
.RS 14n
unsigned long value in decimal
.RE

.sp
.ne 2
.na
\fB\fB{ULONGHEX}\fR\fR
.ad
.RS 14n
unsigned long value in hexadecimal
.RE

.sp
.ne 2
.na
\fB\fB{LONGOCT}\fR\fR
.ad
.RS 14n
long value in octal
.RE

.sp
.ne 2
.na
\fB\fB{ULONGOCT}\fR\fR
.ad
.RS 14n
unsigned long value in octal
.RE

.RE

.RE
.RS +4
.TP
.ie t \(bu
.el o
Reference a structure member. The request form is
\fB{*\fR\fImember\fR\fB,\fR\fI\|base\fR\fB}.\fR \fImember\fR is the member name
whose value is desired, and \fIbase\fR is an \fBadb\fR register name which
contains the base address of the structure. For example, to get the \fBp_pid\fR
field of the \fIproc\fR structure, you would get the \fIproc\fR structure
address in an \fBadb\fR register, for example \fB<f\fR, and write
\fB{*p_pid,<f}\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
Tell \fBadbgen\fR that the offset is valid. The request form is
\fB{OFFSETOK}\fR. This is useful after invoking another \fBadb\fR script which
moves the \fBadb\fR \fIdot\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
Get the size of the \fIstructure\fR. The request form is \fB{SIZEOF}\fR.
\fBadbgen\fR replaces this request with the size of the structure. This is
useful in incrementing a pointer to step through an array of structures.
.RE
.RS +4
.TP
.ie t \(bu
.el o
Calculate an arbitrary C expression. The request form is
\fB{EXPR,\fR\fI\|expression\fR\fB}.\fR \fBadbgen\fR replaces this request with
the value of the expression. This is useful when more than one structure is
involved in the script.
.RE
.RS +4
.TP
.ie t \(bu
.el o
Get the offset to the end of the structure. The request form is \fB{END}\fR.
This is useful at the end of the structure to get \fBadb\fR to align the
\fIdot\fR for printing the next structure member.
.RE
.sp
.LP
\fBadbgen\fR keeps track of the movement of the \fBadb\fR \fIdot\fR and
generates \fBadb\fR code to move forward or backward as necessary before
printing any structure member in a script. \fBadbgen\fR's model of the behavior
of \fBadb\fR's \fIdot\fR is simple: it is assumed that the first line of the
script is of the form \fIstruct_address\fR/\fIadb text\fR and that subsequent
lines are of the form +/\fIadb text\fR. The \fBadb\fR \fIdot\fR then moves in a
sane fashion. \fBadbgen\fR does not check the script to ensure that these
limitations are met. \fBadbgen\fR also checks the size of the structure member
against the size of the \fBadb\fR format code and warns if they are not equal.
.SH OPTIONS
The following option is supported:
.sp
.ne 2
.na
\fB\fB-m\fR \fImodel\fR\fR
.ad
.RS 12n
Specifies the data type model to be used by \fBadbgen\fR for the macro. This
affects the outcome of the \fB{\fR\fIformat specifier\fR\fB}\fR requests
described under \fBDESCRIPTION\fR and the offsets and sizes of data types.
\fImodel\fR can be \fBilp32\fR or \fBlp64\fR. If the \fB-m\fR option is not
given, the data type model defaults to \fBilp32\fR.
.RE

.SH OPERANDS
The following operand is supported:
.sp
.ne 2
.na
\fB\fIfilename\fR\fB\&.adb\fR\fR
.ad
.RS 18n
Input file that contains header information, followed by a null line, the name
of the structure, and finally an \fBadb\fR script.
.RE

.SH EXAMPLES
\fBExample 1 \fRA sample \fBadbgen\fR file.
.sp
.LP
For an include file \fBx.h\fR which contained

.sp
.in +2
.nf
struct x {
         char	*x_cp;
         char	x_c;
         int	x_i;
};
.fi
.in -2
.sp

.sp
.LP
then an \fBadbgen\fR file (call it \fBscript.adb\fR) to print the file
\fBx.h\fR would be:

.sp
.in +2
.nf
#include "x.h"
x
\&./"x_cp"16t"x_c"8t"x_i"n{x_cp,{POINTER}}{x_c,C}{x_i,D}
.fi
.in -2
.sp

.sp
.LP
After running \fBadbgen\fR as follows,

.sp
.in +2
.nf
% /usr/lib/adb/adbgen \|script.adb
.fi
.in -2
.sp

.sp
.LP
the output file \fBscript\fR contains:

.sp
.in +2
.nf
\&./"x_cp"16t"x_c"8t"x_i"nXC3+D
.fi
.in -2
.sp

.sp
.LP
For a macro generated for a 64-bit program using the \fBlp64\fR data model as
follows,

.sp
.in +2
.nf
\fB% /usr/lib/adb/adbgen/ \fR\fB-m\fR\fB lp64 \|script.adb\fR
.fi
.in -2
.sp

.sp
.LP
the output file \fBscript\fR would contain:

.sp
.in +2
.nf
\&./"x_cp"16t"x_c"8t"x_i"nJC3+D
.fi
.in -2
.sp

.sp
.LP
To invoke the script, type:

.sp
.in +2
.nf
example% adb program
x$<script
.fi
.in -2
.sp

.SH FILES
.ne 2
.na
\fB\fB/usr/platform/\fR\fIplatform-name\fR\fB/lib/adb/*\fR\fR
.ad
.sp .6
.RS 4n
platform-specific \fBadb\fR scripts for debugging the 32-bit kernel
.RE

.sp
.ne 2
.na
\fB\fB/usr/platform/\fR\fIplatform-name\fR\fB/lib/adb/sparcv9/*\fR\fR
.ad
.sp .6
.RS 4n
platform-specific \fBadb\fR scripts for debugging the 64-bit SPARC V9 kernel
.RE

.sp
.ne 2
.na
\fB\fB/usr/lib/adb/*\fR\fR
.ad
.sp .6
.RS 4n
\fBadb\fR scripts for debugging the 32-bit kernel
.RE

.sp
.ne 2
.na
\fB\fB/usr/lib/adb/sparcv9/*\fR\fR
.ad
.sp .6
.RS 4n
\fBadb\fR scripts for debugging the 64-bit SPARC V9 kernel
.RE

.SH SEE ALSO
.BR adb (1),
.BR uname (1),
.BR attributes (7),
.BR kadb (8)
.SH DIAGNOSTICS
Warnings are given about structure member sizes not equal to \fBadb\fR format
items and about badly formatted requests. The C compiler complains if a
structure member that does not exist is referenced. It also complains about an
ampersand before array names; these complaints may be ignored.
.SH NOTES
\fIplatform-name\fR can be found using the \fB-i\fR option of \fBuname\fR(1).
.SH BUGS
\fBadb\fR syntax is ugly; there should be a higher level interface for
generating scripts.
.sp
.LP
Structure members which are bit fields cannot be handled because C will not
give the address of a bit field. The address is needed to determine the offset.
